<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>查找重复元素</title>
	</head>
	<body>
		<h4>题目描述</h4>
		<p>找出数组 arr 中重复出现过的元素</p>
		<span>duplicates([1, 2, 4, 4, 3, 3, 1, 5, 3]).sort()</span>
		<script>
			function duplicates(a){
				var arr = a;
				var no_repeat_arr = [];
				var repeat_arr = [];
				var result = [];
				arr.forEach( (i,index,array) => {
					if ( no_repeat_arr.indexOf(i) == -1 ){
						no_repeat_arr.push(i);
					} else{
						repeat_arr.push(i);
					}
				});
				repeat_arr.filter( (i) => {
					if ( result.indexOf(i) == -1 ){
						result.push(i);
					}
				});
				return result;
			}
			


			console.log(duplicates([1, 2, 4, 4, 3, 3, 1, 5, 3]).sort());
		</script>
	</body>
</html>
